using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using ESRI.ArcGIS.ADF.BaseClasses;
using ESRI.ArcGIS.ADF.CATIDs;
using ESRI.ArcGIS.Framework;
using ESRI.ArcGIS.ArcMapUI;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.esriSystem;

namespace BesAsm.Emgaats.TracerUI
{
  /// <summary>
  /// Summary description for PerformTraceCommand.
  /// </summary>  
  [ClassInterface(ClassInterfaceType.None)]
  public sealed class PerformTraceCommand : ESRI.ArcGIS.Desktop.AddIns.Button
  {        
    private TracerExtension _tracerExtension;

    /// <summary>
    /// Initializes a new instance of the <see cref="PerformTraceCommand"/> class.
    /// </summary>
    public PerformTraceCommand()
    {      
      ESRI.ArcGIS.esriSystem.UID u;
      u = new ESRI.ArcGIS.esriSystem.UIDClass();
      u.Value = ThisAddIn.IDs.TracerExtension;
      _tracerExtension = (TracerExtension)ArcMap.Application.FindExtensionByCLSID(u);
    }

    /// <summary>
    /// Occurs when this command is clicked
    /// </summary>
    protected override void OnClick()
    {
      try
      {
        _tracerExtension.Trace();
      }
      catch (Exception ex)
      {
        MessageBox.Show(ex.Message, "Error Using Tracer");
        return;
      }
    }

  }
}
